package com.edu.exam.entity.curriculum.questionbank;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;

// External enum imports
import com.edu.exam.enums.curriculum.questionbank.MetricLevel;
import com.edu.exam.enums.curriculum.questionbank.StandardMetricType;

/**
 * 质量评估指标实体类
 * 所属模块：B-02 题库管理模块
 * 对应数据库表：mcq_assessment_metrics
 *
 * 管理多选题质量评估的具体指标数据，包含指标名称、得分、权重、等级、详细评估结果和评估意见。
 * 支持细粒度的质量指标管理，包括内容质量、选项干扰性、难度准确性等多个维度的评估。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Comment("质量评估指标表")
@SQLDelete(sql = "UPDATE mcq_assessment_metrics SET is_deleted = true, delete_time = CURRENT_TIMESTAMP WHERE id = ?")
@Where(clause = "is_deleted = false")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class MultipleChoiceAssessmentMetric {

    /**
     * 评估指标唯一标识符
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 关联的质量评估ID
     */
    @NotNull(message = "质量评估ID不能为空")
    @Column(name = "assessment_id", nullable = false)
    private Long assessmentId;

    /**
     * 指标名称
     */
    @NotBlank(message = "指标名称不能为空")
    @Size(max = 100, message = "指标名称长度不能超过100个字符")
    @Column(name = "metric_name", nullable = false, length = 100)
    private String metricName;

    /**
     * 指标得分 (0-100)
     */
    @NotNull(message = "指标得分不能为空")
    @Column(name = "metric_score", nullable = false, precision = 5, scale = 2)
    private BigDecimal metricScore;

    /**
     * 指标权重 (0.1-2.0)
     */
    @NotNull(message = "指标权重不能为空")
    @Column(name = "metric_weight", nullable = false, precision = 3, scale = 2)
    @Builder.Default
    private BigDecimal metricWeight = BigDecimal.ONE;

    /**
     * 指标等级
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "metric_level", length = 20)
    private MetricLevel metricLevel;

    /**
     * 指标详细评估结果
     */
    @Column(name = "metric_details", columnDefinition = "TEXT")
    private String metricDetails;

    /**
     * 评估意见和说明
     */
    @Column(name = "comments", columnDefinition = "TEXT")
    private String comments;

    /**
     * 创建时间
     */
    @NotNull(message = "创建时间不能为空")
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 软删除标记
     */
    @NotNull(message = "删除标记不能为空")
    @Column(name = "is_deleted", nullable = false)
    @Builder.Default
    private Boolean isDeleted = false;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    @PrePersist
    protected void onCreate() {
        LocalDateTime now = LocalDateTime.now();
        this.createTime = now;
        if (this.metricLevel == null) {
            this.metricLevel = MetricLevel.fromScore(this.metricScore);
        }
    }

    
}